var memberUtil=require('../../../utils/memberUtil');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mycahuo:null,
  myteam:null,
    vips:[
      {index:0,name:"vip0",icon:"/images/icon/svip_00.png",desc:"登录、注册，没有产生任何消费，等级为注册会员。可获得佣金金额，佣金金额只显示，不能提现。"},
      {index:1,name:"vip1",icon:"/images/icon/svip_01.png",desc:"充值消费大于等于1元且小于2000元，获得消费新人等级。佣金金额只显示，不能提现。"},
      {index:2,name:"vip2",icon:"/images/icon/svip_02.png",desc:"充值消费大于等于2000元且小于20000元，可提现直属团队（当前会员的第一级团队）消费额25%佣金额，结存直属团队10%于个人待提帐户显示中，也可提现直属团队下一级（当前会员的第二级团队）销售额的8%。同时可提现补齐vip1时的结余佣金。"},
      {index:3,name:"vip3",icon:"/images/icon/svip_03.png",desc:"充值消费大于等于20000元，获得并可提现直属团队消费35%佣金，并补齐vip2时结余佣金，同样有权获得并提现直属团队下一级销售额的8%销售佣金。"},
      {index:4,name:"vip4",icon:"/images/icon/svip_04.png",desc:"自消费（充值消费）达到2万元，本人扫码的直属一级团队消费累计达10万元时，升级为店长，除vip3的特权外，还享受店铺补贴。此项特权财务以对公形式结算；"},
    ],
    vipsshop:[
      {index:0,name:"擦火会员",icon:"/images/icon/dvip_00.png"},
      {index:1,name:"消费新人",icon:"/images/icon/dvip_01.png"},
      {index:2,name:"消费能人",icon:"/images/icon/dvip_02.png"},
      {index:3,name:"消费达人",icon:"/images/icon/dvip_03.png"},
      {index:4,name:"店长1",icon:"/images/icon/dp_01.png"},
    ],
    vip:0,
    baseImageUrl:app.globalData.baseUrl
  },
  /**个人资料跳转 */
  myUserInfoNavigate:function(){
    wx.navigateTo({
      url: '/pages/my/myuserinfo'
    })
  },
  showScene:function(){
    wx.navigateTo({
      url: '/pages/shop/qrscene'
    })
  },
  personalDocument:function(){
    wx.navigateTo({
      url: '/pages/my/personalDocument'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var resss=(wx.getStorageSync("loginUserInfo").userInfo==undefined?"":wx.getStorageSync("loginUserInfo").userInfo);
    that.setData({
      userInfo:resss
    })
    if(that.data.userInfo.id==undefined) {
      memberUtil.getLogin(app,0,1,that,2);
    }
  },
  //卡卷提示
  kajuan:function(){
    wx.showToast({
      title: '此模块工程师正在积极升级，敬请期待！',
      icon: 'none',
      duration: 3000
    })
  },
  //我的会员跳转
  myhuiyuan:function(){
    wx.navigateTo({
      url: "/pages/my/myAccount"
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    var memberIdJson = { memberId:that.data.userInfo.id}
    wx.request({
      url: app.globalData.baseUrl+'/member/findMemberBaseInfoByMemberId',
      header: app.globalData.headerPost,
      method: 'POST',
      data:JSON.stringify(memberIdJson),
      success:function(res) {
        if (Number(res.statusCode) == 200 && res.data.username) {
          that.setData({
            userDataInfo: res.data
          })
        } else {
          that.setData({
            userDataInfo: []
          })
           /* wx.showModal({
                title: '您还没有完善用户信息，赶紧去完善吧？',
                content: '',
                success: function (res) {
                    if (res.confirm) {
                        wx.navigateTo({
                            url: '/pages/my/personalDocument'
                        })
                    }
                }
            });
            return false;*/
        }
      }
    })
    wx.request({
      url: app.globalData.baseUrl+ '/member/findICCCGByMemberId',
      method: 'POST',
      data: JSON.stringify(memberIdJson),
      success:function(e){
        if(e.statusCode==200){
          var vip=Number(e.data.data.memberGrade.replace("vip",""));
          that.setData({
            mycahuo:e.data.data,
            vip:vip
          })
        }else{
          that.setData({
            mycahuo:[],
            vip:0
          })
        }
      },
      fail:function(){

      }
    })

    //调用我的团队
    wx.request({
      url: app.globalData.baseUrl + '/member/myTeamList',
      method: 'POST',
      data: JSON.stringify(memberIdJson),
      success: function (e) {
        if (e.statusCode == 200) {
          that.setData({
            myteam: e.data
          })
        }
      },
      fail: function () {

      }
    })

    //调用我的佣金====每月收益
    wx.request({
      url: app.globalData.baseUrl + '/member/thisMonthCommissionAmount',
      method: 'POST',
      data: JSON.stringify(memberIdJson),
      success: function (e) {
        if (e.statusCode == 200) {
          that.setData({
            monthcommissionAmount: e.data.data
          })
        }
      },
      fail: function () {

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that=this;
    return {
      title: '我的二维码',
      path: "/pages/shop/shareSuccess?parentId=" + that.data.userInfo.id + "&enterType=0",
      imageUrl: app.globalData.loginUserInfo.erweimaUrl
    }
  }
})